/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sd.chat;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.*;

/* ImageFileView.java is used by FileChooserDemo2.java. */
public class ImageFileView extends FileView {

    ImageIcon jpgIcon;
    ImageIcon gifIcon;
    ImageIcon tiffIcon;
    ImageIcon pngIcon;

    public ImageFileView() {
        try {
            jpgIcon = new ImageIcon(ImageIO.read(new URL("http://www.arteladecasa.com/downloads/javaupload/nopic/jpgIcon.gif")));
            gifIcon = new ImageIcon(ImageIO.read(new URL("http://www.arteladecasa.com/downloads/javaupload/nopic/gifIcon.gif")));
            tiffIcon = new ImageIcon(ImageIO.read(new URL("http://www.arteladecasa.com/downloads/javaupload/nopic/tiffIcon.gif")));
            pngIcon = new ImageIcon(ImageIO.read(new URL("http://www.arteladecasa.com/downloads/javaupload/nopic/pngIcon.gif")));
        } catch (IOException erro) {
        }
    }

    public String getName(File f) {
        return null; //let the L&F FileView figure this out
    }

    public String getDescription(File f) {
        return null; //let the L&F FileView figure this out
    }

    public Boolean isTraversable(File f) {
        return null; //let the L&F FileView figure this out
    }

    public String getTypeDescription(File f) {
        String extension = Utils.getExtension(f);
        String type = null;

        if (extension != null) {
            if (extension.equals(Utils.jpeg)
                    || extension.equals(Utils.jpg)) {
                type = "JPEG Image";
            } else if (extension.equals(Utils.gif)) {
                type = "GIF Image";
            } else if (extension.equals(Utils.tiff)
                    || extension.equals(Utils.tif)) {
                type = "TIFF Image";
            } else if (extension.equals(Utils.png)) {
                type = "PNG Image";
            }
        }
        return type;
    }

    public Icon getIcon(File f) {
        String extension = Utils.getExtension(f);
        Icon icon = null;

        if (extension != null) {
            if (extension.equals(Utils.jpeg) ||
                extension.equals(Utils.jpg)) {
                icon = jpgIcon;
            } else if (extension.equals(Utils.gif)) {
                icon = gifIcon;
            } else if (extension.equals(Utils.tiff) ||
                       extension.equals(Utils.tif)) {
                icon = tiffIcon;
            } else if (extension.equals(Utils.png)) {
                icon = pngIcon;
            }
        }
        return icon;
    }
}